package com.itcam.iostream;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * Author:Cammy.Wu
 * Date:2024-05-13
 * Description:
 */

public class CharStreamDemo01 {
    public static void main(String[] args) throws IOException {
        // 文件->程序：
        // 1.有一个文件：创建一个file类对象
        File file = new File("e:\\IOstream\\IO_File_CharStream01.txt");
        // 2.利用FileReader这个流，怼到源文件上->创建一个FileReader的流的对象
        FileReader fr = new FileReader(file);
        // 进行操作“吸”的动作->读取文件
//        int read1 = fr.read();
//        int read2 = fr.read();
//        int read3 = fr.read();
//        int read4 = fr.read();
//        int read5 = fr.read();
//        int read6 = fr.read();
//        int read7 = fr.read();
//        System.out.print("read = " + (char)read1);
//        System.out.print("read = " + (char)read2);
//        System.out.print("read = " + (char)read3);
//        System.out.print("read = " + (char)read4);
//        System.out.print("read = " + (char)read5);
//        System.out.print("read = " + (char)read6);
//        System.out.print("read = " + (char)read7);
        // 方式一
//        int r=fr.read();
//        while(r!=-1){
//            System.out.print((char)r);
//            r=fr.read();
//        }
        // 方式二
        int r;
        while ((r = fr.read()) != -1) {
            System.out.print((char) r);
        }
        // 关闭流
        fr.close();
    }
}
